using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using Friso.Business;
using Friso.Entities;
using FetCo.Framework;

/// <summary>
/// Summary description for UserRight
/// </summary>
public class UserRight
{
    public static long GetUserId(string name)
    {
        Criteria cri = new Criteria();
        cri.add(UserColumns.UserName, name, Condition.EQUAL, Condition.AND);
        UserCollection userCollection = UserService.GetUserListByParam(UserColumns.UserId, OrderDirection.ASC, cri.Criter);
        if (userCollection.Count > 0)
            return userCollection[0].PermissionId;
        return -1;
    }
    public static long GetUserId_(string name)
    {
        Criteria cri = new Criteria();
        cri.add(UserColumns.UserName, name, Condition.EQUAL, Condition.AND);
        UserCollection userCollection = UserService.GetUserListByParam(UserColumns.UserId, OrderDirection.ASC, cri.Criter);
        if (userCollection.Count > 0)
            return userCollection[0].UserId;
        return -1;
    }
    public static string GetUserPermission()
    {
        long UId = GetUserId(HttpContext.Current.User.Identity.Name);
        string p = string.Empty;
        Permission _Permission = PermissionService.GetPermission(int.Parse(UId.ToString()));
        if (_Permission != null)
        {
            switch (_Permission.Code)
            {
                case FetConstant.TacGia:
                    p = FetConstant.TacGia;
                    break;
                case FetConstant.BienTap:
                    p = FetConstant.BienTap;
                    break;
                case FetConstant.XuatBan:
                    p = FetConstant.XuatBan;
                    break;
                case FetConstant.Admin:
                    p = FetConstant.Admin;
                    break;
                case FetConstant.UserRoot:
                    p = FetConstant.Admin;
                    break;
            }
        }
        return p;
    }
}
